//
// Created by ChenJi on 2021/4/13.
//

#ifndef WARNER_2_DATA_CENTER_H
#define WARNER_2_DATA_CENTER_H

#endif //WARNER_2_DATA_CENTER_H

#include "main.h"
#include "W25QXX.h"

#define getWarnerEventAddress(i) i*11+0x100000
#define getWarnerEventSyncAddress(i) i*11+0x100000+10
#define INDEX_ADDRESS 0xFFFFE
#define EVENT_TYPE_ONLINE 1
#define EVENT_TYPE_TIMEOUT 2
#define EVENT_TYPE_OFFLINE 3
#define EVENT_TYPE_SETDEFEAT 5
#define EVENT_TYPE_RESETDEFEAR 4
#define EVENT_TYPE_OPENDOOR 7
#define EVENT_TYPE_CLOSEDOOR 8
#define EVENT_TYPE_RADERWARN 9

void listLog();

void loadIndex();

uint16_t getIndex();

typedef struct {
    uint16_t id;
    uint8_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    uint8_t event_type;
    uint8_t synchronized;
} Warner_Event;

Warner_Event *addEvent(uint8_t event_type);

void system_logger_init();

Warner_Event *setEvent(uint16_t event_id, uint8_t event_type);

void setIndex(uint16_t index);

void getEvent(uint16_t index);

void saveEvent(Warner_Event *event);

Warner_Event *readEvent(uint16_t index);

uint8_t containEvent(uint16_t index);

uint8_t chengeSyncState(uint8_t mode, uint16_t id);

void sendEventToServer(uint8_t event_id);

uint8_t *getOriginEventData(uint16_t index);


void loadConfig();

void readConfig();

void saveConfig();

void resetConfig();

void setStartTime(uint8_t h, uint8_t m, uint8_t s);

void setEndTime(uint8_t h, uint8_t m, uint8_t s);

void getStartTime(uint8_t *data);

void getEndTime(uint8_t *data);

void enableAutoSet();

void disableAutoSet();

uint8_t isAutoSetMode();

void enableDefeatState();

void disableDefeatState();

void data_center_debug_sync(char *data);

void data_center_debug_sync_process(char *data);

void data_center_debug_sync_process_done();

void data_center_print_number_hex(int32_t number);

void data_center_print_number_hex(int32_t number);

void print_config_information(char *inf_name, uint32_t value, uint8_t radix, uint8_t is_bool);